<template>
  <div class="Main">
    <!--头部-->
    <div class="Banner">
      <img src="../assets/bg_17670e3.jpg" alt="">
      <div class="Banner-title">{{ typeInfo.label }}</div>
    </div>
    <div class="Content">
      <!--列表-->
      <div class="ListContent">
        <div class="unData" v-if="videoList.length===0">
          <el-empty description="暂无数据"></el-empty>
        </div>
        <template v-if="videoList.length>0">
          <div class="ListContent-list">
            <div class="ListContent-liItem" v-for="video in videoList" @click="toVideoDetails(video)">
              <div class="ListContent-listItem">
                <div class="ListContent-itemImg">
                  <div class="playIcon">
                    <i class="el-icon-video-play"></i>
                  </div>
                  <div class="video-icon-label">
                    <div class="icon">
                      <div class="iconfont icon-tuya-"></div>
                      <div>{{ video.views | numberFilter }}</div>
                    </div>
                    <div class="icon">
                      <div class="iconfont icon-dianzan_kuai"></div>
                      <div>{{ video.likes | numberFilter }}</div>
                    </div>
                  </div>
                  <img :src="video.coverPath|imgSrcFormat" alt=""/>
                </div>
                <div class="ListContent-itemDetail">
                  {{ video.title }}
                </div>
              </div>
            </div>
          </div>
        </template>
      </div>
      <!--分页器-->
      <div class="paginationView" v-if="pageInfo.total>20">
        <el-pagination
          background
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :page-size="pageInfo.pageSize"
          :current-page.sync="pageInfo.pageNum"
          :total="pageInfo.total">
        </el-pagination>
      </div>

    </div>
  </div>
</template>

<script>
import videoApi from "@/api/video";

export default {
  name: "Type",
  data() {
    return {
      typeId: "",
      typeInfo: {},
      videoList: [],
      pageInfo: {
        pageNum: 1,
        pageSize: 20,
        total: 0
      }
    };
  },
  methods: {
    saveAndGetTypeIdSession() {
      if (this.$route.params.typeId === undefined) {
        let sessionTypeId = sessionStorage.getItem("typeId");
        sessionTypeId ? this.typeId = sessionTypeId : this.$router.push("/");
      } else {
        this.typeId = this.$route.params.typeId;
        sessionStorage.setItem("typeId", this.$route.params.typeId);
      }
      this.getTypeDetailInfo();
    },
    async getTypeDetailInfo() {
      let form = {
        id: this.typeId,
        pageNum: this.pageInfo.pageNum,
        pageSize: this.pageInfo.pageSize
      };
      let {data: {typeInfo, videoList, total}} = await videoApi.getDetailTypeInfoById(form);
      this.typeInfo = typeInfo;
      this.videoList = videoList;
      this.pageInfo.total = total;
    },
    /*分页器*/
    handleCurrentChange(pageNum) {
      this.pageInfo.pageNum = pageNum;
      this.getCommentList();
    },
    toVideoDetails(video) {
      this.$router.push({
        name: "details",
        params: {
          videoId: video.id
        }
      });
    }
  },
  created() {
    this.saveAndGetTypeIdSession();
  }
};
</script>

<style scoped lang="less">
.Banner {
  height: 160px;
  position: relative;
  width: 100%;

  img {
    height: 100%;
    width: 100%;
  }

  .Banner-title {
    position: absolute;
    top: 80px;
    left: 180px;
    font-size: 24px;
    font-weight: 400;
    text-align: left;
    color: #fff;
    line-height: 33px;
  }
}

.Content {
  max-width: 1220px;

  padding: 0 6px;
  margin: 0 auto;


  .ListContent {
    margin-top: 25px;
    margin-bottom: 40px;
    min-height: 600px;

    .ListContent-list {
      min-height: 540px;
      text-align: justify;
      background-color: #fff;

      .ListContent-liItem {
        display: inline-block;
        margin: 0 5px;

        .ListContent-listItem {
          margin-bottom: 20px;
          overflow: hidden;
          display: inline-block;
          vertical-align: top;
          width: 231px;
          color: #333;
          text-decoration: none;
          cursor: pointer;


          .ListContent-itemImg {
            border-radius: 5px;
            overflow: hidden;
            text-align: center;
            background-color: #d8d8d8;
            height: 134px;
            position: relative;

            &:hover {
              & .video-icon-label {
                display: none;
              }

              & .playIcon > .el-icon-video-play {
                display: inline-block;
                animation-name: scale;
                animation-duration: .3s;
              }
            }

            img {
              width: 100%;
              height: 100%;
            }

            .playIcon {
              .el-icon-video-play {
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%);
                color: white;
                transition: all .3s ease-in-out;
                display: none;
                font-size: 50px;
              }
            }

            .video-icon-label {
              display: flex;
              position: absolute;
              bottom: 0;
              left: 0;
              padding: 5px 10px;

              .icon {
                font-size: 12px;
                margin-right: 9px;
                color: white;
                display: flex;
                line-height: 16px;

                .iconfont {
                  font-size: 14px;
                  margin-right: 4px;
                }
              }
            }
          }

          .ListContent-itemDetail {
            margin-top: 10px;
            display: block;
            overflow: hidden;
            width: 100%;
            height: 45px;
            font-size: 13px;
          }
        }
      }
    }
  }

  .paginationView {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
  }
}

@keyframes scale {
  from {
    font-size: 200px;
  }
  to {
    font-size: 50px;
  }

}
</style>
